package cn.iocoder.yudao.module.lfd.service.barber;

import cn.iocoder.yudao.module.lfd.enums.ErrorCodeConstants;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.lfd.controller.admin.barber.vo.*;
import cn.iocoder.yudao.module.lfd.dal.dataobject.barber.BarberDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.lfd.convert.barber.BarberConvert;
import cn.iocoder.yudao.module.lfd.dal.mysql.barber.BarberMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 理发师 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class BarberService{

    @Resource
    private BarberMapper barberMapper;

    
    public Long createBarber(BarberCreateReqVO createReqVO) {
        // 插入
        BarberDO barber = BarberConvert.INSTANCE.convert(createReqVO);
        barberMapper.insert(barber);
        // 返回
        return barber.getId();
    }

    
    public void updateBarber(BarberUpdateReqVO updateReqVO) {
        // 校验存在
        validateBarberExists(updateReqVO.getId());
        // 更新
        BarberDO updateObj = BarberConvert.INSTANCE.convert(updateReqVO);
        barberMapper.updateById(updateObj);
    }

    
    public void deleteBarber(Long id) {
        // 校验存在
        validateBarberExists(id);
        // 删除
        barberMapper.deleteById(id);
    }

    private void validateBarberExists(Long id) {
        if (barberMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.BARBER_NOT_EXISTS);
        }
    }

    
    public BarberDO getBarber(Long id) {
        return barberMapper.selectById(id);
    }

    
    public List<BarberDO> getBarberList(Collection<Long> ids) {
        return barberMapper.selectBatchIds(ids);
    }

    
    public PageResult<BarberDO> getBarberPage(BarberPageReqVO pageReqVO) {
        return barberMapper.selectPage(pageReqVO);
    }

    
    public List<BarberDO> getBarberList(BarberExportReqVO exportReqVO) {
        return barberMapper.selectList(exportReqVO);
    }

    
    public List<BarberDO> getAll() {
        return barberMapper.selectList();
    }

}
